<%@page import="com.netistate.pojo.Labor"%>
<%@page import="com.netistate.pojo.User"%>
<%@page import="com.netistate.pojo.Project"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.Timestamp"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Calendar"%>
<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/default.css" />
	<script type="text/javascript"  src="${pageContext.request.contextPath}/js/common.js"></script>
	<script type="text/javascript"  src="${pageContext.request.contextPath}/js/table.js"></script>
	<script type="text/javascript"  src="${pageContext.request.contextPath}/js/trash.js"></script>
	<script type="text/javascript"  src="${pageContext.request.contextPath}/plugin/msgbox/msgbox.js"></script>
	<script type="text/javascript"  src="${pageContext.request.contextPath}/jsp/labor/labor.js"></script>
	<script type="text/javascript"  src="${pageContext.request.contextPath}/jsp/project/project.js"></script>
	<script type="text/javascript"  src="${pageContext.request.contextPath}/plugin/calendar/Calendar.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/jsp/project/project.js"></script>
	<script type="text/javascript" >
	  function add(){
	     PigossMsg.show("${pageContext.request.contextPath}/jsp/labor/addLabor.jsp","添加工时",400,390,"AddLabor.saveConfig()");
	  }
	  function delLabor(id,msg){
	        this.msg = msg;
	        PigossMsg.confirm(this.msg,null,function yesHandler(){EditLabor.del(id)},function noHandler(){});
	  
	   };
	   function isValid(){
	       var  dayStart=document.getElementById("dayStart").value;
	       var  dayEnd=document.getElementById("dayEnd").value;
	       if(dayStart!="7天前" && dayEnd!="现在"){
	           dayStart=dayStart.split("-");
		       dayEnd=dayEnd.split("-");
		       var timeStart=new Date(dayStart[0],dayStart[1],dayStart[2]);
		       var timeEnd=new Date(dayEnd[0],dayEnd[1],dayEnd[2]);
		       if(timeStart>=timeEnd){
		          PigossMsg.alert("开始时间必须小于结束时间！");
		          return false;
		       }
	       }
	   }
	   //显示工时查询下拉
	   function showLaborQuery(){
	   		var idDiv = document.getElementById('query_labor_condition');
	   		
	        if(idDiv.style.display=='none'){
	            idDiv.style.display='block'; 
	        }else{
	           idDiv.style.display='none'; 
	        };
	        
	   };
	   //切换工时统计
	   function lookLaborStat(){
   			AjaxUtil.request({
				url : 'look_labor_stat.action',
				params : {},
				success : function(responseText){
   					window.parent.document.getElementById("mainFrame").src="${pageContext.request.contextPath}/jsp/labor/laborStat.jsp";
				},
				failure : function(){
				}
			});
   		};
 
	</script>
	<style type="text/css">
		.overTd {table-layout:fixed}
		.overTd td{text-overflow:ellipsis;overflow:hidden;white-space:nowrap;padding:0px}
    </style>
	</head>
	<body>
	
		<div id="xtab">
			<a id="rightDiv0_tab" href="#" class='homelink curren' onclick=""><span style="cursor:pointer;">工时服务</span></a>
			<a id="rightDiv1_tab" href="#" class='homelink' onclick="lookLaborStat()"><span style="cursor: pointer;">工时统计</span></a>
		</div>
		<div class="toolbar">
			<a id="addLabor" href="#" class='buttonlink txbtip' title='添加工时' onclick="add()"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/plus.png'/>添加工时</a>
			<a href="#" class='buttonlink txbtip' title='工时查询' onclick="showLaborQuery()"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/search.png'/>工时查询</a>
		</div>
		<div id="query_labor_condition" class="toolbar" style="display:block;height:40;overflow-y:hidden;overflow-x:hidden">
		    <form name="query_labor_by_condition" action="query_labor_by_condition.action" method="post" onSubmit="">
				<div class="query" >
					<table id="projectTable" width="400px">
						<tr>
							<td class="td_title" title="项目名称">项目名称:</td>
							<td>
								 <select id="projectName" name="projectName" style="width:140px;" size="1">
								   <%List<Project> projectList = (List<Project>)request.getSession().getAttribute("projectList");
									String queryProjectNameId = (String)request.getAttribute("queryProjectNameId");
									Project project = (Project)request.getAttribute("queryLaborPidProject");
									
									if("所有".equals(queryProjectNameId) || queryProjectNameId == null){%>
									<option title="所有" selected value="所有">所有</option>
									<%	for(Project p : projectList){ %>
										<option title="<%=p.getProjectName()%>" value="<%=p.getId() %>"><%=p.getProjectName()%></option>
									<% 	}
									}else{%>
									<option title="所有" selected value="所有">所有</option>
									<%	for(Project p : projectList){ 
											if(p.getId() == Integer.parseInt(queryProjectNameId)){%>
											<option title="<%=project.getProjectName()%>" selected value="<%=project.getId() %>"><%=project.getProjectName()%></option>
										<%	} else { %>
											<option title="<%=p.getProjectName()%>" value="<%=p.getId() %>"><%=p.getProjectName()%></option>
									<% 		}	
										}
									} %>
					             </select>
							</td>
							<td class="td_title" title="成员">成员:</td>
							<td>
							    <select id="laborUser" name="laborUser"  style="width:100px">
							     <%	List<User> userList = (List<User>)request.getSession().getAttribute("userList");
									String queryLaborUser = (String)request.getAttribute("queryLaborUser");
									User queryLaborPidUser = (User)request.getAttribute("queryLaborPidUser");
									if("所有".equals(queryLaborUser) || queryLaborUser == null){%>
									<option title="所有" selected value="所有">所有</option>
								<%		for(User u : userList){ %>
										<option value="<%=u.getId()%>"><%=u.getRealName()%></option>
								<%		}
									}else{ %>
									<option title="所有" selected value="所有">所有</option>
								<%		for(User u : userList){
											if(queryLaborPidUser.getUsername().equals(u.getUsername())){%>
											<option selected value="<%=queryLaborPidUser.getId()%>"><%=queryLaborPidUser.getRealName()%></option>
								<%			} else {%>
									<option value="<%=u.getId()%>"><%=u.getRealName()%></option>
								<%			}
										}
									}	%>
							    </select>
							</td>
							<td class="td_title" title="所属部门">所属部门:</td>
							<td>
								<select id="section" name="section">
							<%	 String queryLaborSection = (String)request.getAttribute("queryLaborSection");
								 if(queryLaborSection == null){%>
								     <option title="所有" value="所有">所有</option>
						             <option title="研发" value="研发">研发</option>
						             <option title="技术支持" value="技术支持">技术支持</option>
						             <option title="交流" value="交流">交流</option>
						             <option title="销售" value="销售">销售</option>
							<%	}else{%>
									<option title="<%=queryLaborSection %>" value="<%=queryLaborSection %>"><%=queryLaborSection %></option>
							<%		if(!queryLaborSection.equals("所有")){ %>
								     <option title="所有" value="所有">所有</option>
							<%		}
								     if(!queryLaborSection.equals("研发")){	%>
								     <option title="研发" value="研发">研发</option>
							<% 		}
								     if(!queryLaborSection.equals("技术支持")){ %>
								     <option title="技术支持" value="技术支持">技术支持</option>
							<%		}
								     if(!queryLaborSection.equals("交流")){ %>
								     <option title="交流" value="交流">交流</option>
							<%		}
								     if(!queryLaborSection.equals("销售")){ %>
								     <option title="销售" value="销售">销售</option>
							<%		}
								 } %>
					            </select>
							</td>
							<td class="td_title" title="阶段">阶段:</td>
							<td>
								<select id="state" name="state">
							<%	 String queryLaborState = (String)request.getAttribute("queryLaborState");
								 if(queryLaborState == null){ %>
								       <option value="所有">所有</option>
								       <option value="售前">售前</option>
									   <option value="已签单">已签单</option>
									   <option value="实施">实施</option>
									   <option value="已验收">已验收</option>
									   <option value="停滞">停滞</option>
							<%	}else{ %>
								     <option title="<%=queryLaborState %>" value="<%=queryLaborState %>"><%=queryLaborState %></option>
							<%		if(!queryLaborState.equals("所有")){ %>
								         <option title="所有" value="所有">所有</option>
							<%		}
								     if(!queryLaborState.equals("售前")){%>
								         <option title="售前" value="售前">售前</option>
							<%		}
								     if(!queryLaborState.equals("已签单")){ %>
								         <option title="已签单" value="已签单">已签单</option>
							<%		}
								     if(!queryLaborState.equals("实施")){%>
								         <option title="实施" value="实施">实施</option>
							<%		}
									if(!queryLaborState.equals("已验收")){%>
								         <option title="已验收" value="已验收">已验收</option>
							<%		}
									if(!queryLaborState.equals("停滞")){%>
								         <option title="停滞" value="停滞">停滞</option>
							<%		}
								 }%>
					            </select>
							</td>
							<td class="td_title" title="日期">日期:</td>
							<td>
							<%	Date date = new Date();
							    SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");
							    String endString = sdFormat.format(date);
							    Calendar calendar = Calendar.getInstance();
							    calendar.setTime(date);
							    calendar.add(Calendar.DATE,-7);
							    Date date2 = calendar.getTime();
							    String startString = sdFormat.format(date2);
							    String dayStart = (String)request.getAttribute("queryLaborbeginTime");
							    String dayEnd = (String)request.getAttribute("queryLaborEndTime");
							    if(dayStart != null){
							         startString = dayStart;
							    }
							    if(dayEnd != null){
							         if(endString.equals(dayEnd)){
							             endString = "现在";
							         }else{
							              endString = dayEnd;
							         }
							    }else{
							        endString = "现在";
							    }
							 %>
								<input id="beginTime" name="beginTime" type="text" style="width:80px"
							onclick="MyCalendar.SetDate(this)" value="<%=startString %>"
							readonly="readonly" />
							</td>
							<td title="到">到</td>
							<td>
								<input id="endTime" name="endTime" type="text" style="width:80px"
							onclick="MyCalendar.SetDate(this)" value="<%=endString %>"
							readonly="readonly" />
							</td>
							<td class="td_title" title="是否去现场">
								是否去现场:
							</td>
							<td class="td_title">
							   <select style="width:90px" id="locale" name="isLocale">
							   	<% String queryIsLocale = (String)request.getAttribute("queryIsLocale");
							       if(queryIsLocale == null){ %>
							          <option title="不限" value="不限">不限</option>
								      <option title="有现场服务" value="1">有现场服务</option>
								      <option title="无现场服务" value="0">无现场服务</option>
							   	<% }else{
							         if(queryIsLocale.equals("1")){ %>
								         <option title="有现场服务" value="<%=queryIsLocale %>">有现场服务</option>
								<%
							         }else if(queryIsLocale.equals("0")){ %>
								         <option title="无现场服务" value="<%=queryIsLocale %>">无现场服务</option>
								<%	 }else{ %>
							            <option title="<%=queryIsLocale %>" value="<%=queryIsLocale %>"><%=queryIsLocale %></option>
							    <%	 }
							         if(!queryIsLocale.equals("不限")){%>
							            <option title="不限" value="不限">不限</option>
							    <%	 }
							         if(!queryIsLocale.equals("1")){%>
							            <option title="有现场服务" value="1">有现场服务</option>
							    <%	 }
							         if(!queryIsLocale.equals("0")){%>
							            <option title="无现场服务" value="0">无现场服务</option>
							    <%	 }
							      }%>
							   </select>
							</td>
							<td class="td_title">
							  <input title="查询" type="submit" id="queryButtonSubmit" value="查询" />
							</td>
							<td class="td_title">&nbsp;&nbsp;</td>
							<td class="td_title">&nbsp;&nbsp;</td>
						</tr>
					</table>
				</div>
			</form>
		</div>
		<div id="show_labor_query" style="width:100%;height:88%; overflow-y:scroll; border:1px solid;" >
			<table id="dArticleList" width="100%" border="0" cellpadding="0" cellspacing="1"  class="resizable overTd">
				<thead>
					<tr class="fixHead">
						<td class="td1" style="cursor:pointer" width="10%">项目名称</td>
						<td class="td1" style="cursor:pointer" width="10%">项目参与者</td>
						<td class="td1" style="cursor:pointer" width="10%">工时</td>
						<td class="td1" style="cursor:pointer" width="15%">日期</td>
						<td class="td1" style="cursor:pointer" width="7%">是否去现场</td>
						<td class="td1" style="cursor:pointer" width="10%">阶段</td>
						<td class="td1" style="cursor:pointer" width="30%">描述</td>
						<td class="td1" width="10%">操作</td>
					</tr>
			    </thead>
				<tbody>
				<%
					List<Labor> list = new ArrayList<Labor>();
					List<Labor> laborList = (List<Labor>)request.getAttribute("lList");
					if(laborList == null){
						list = (List<Labor>)request.getSession().getAttribute("laborList");
					}else{
						list = laborList;
					}
					for(Labor l : list){
					%>
					<tr onMouseOver= "this.bgColor   =   '#cccccc '; "   onMouseOut= "this.bgColor   =   '#FFFFFF'; " >  
			       		<td title="<%=l.getProject().getProjectName() %>" align="center" class="td2 txbtip" ><%=l.getProject().getProjectName() %>&nbsp;</td>
			       		<td title="<%=l.getUser().getRealName() %>" align="center" class="td2 txbtip" ><%=l.getUser().getRealName() %>&nbsp;</td>
			       		<td title="<%=l.getHours() %>" align="center" class="td2 txbtip" ><%=l.getHours() %>&nbsp;</td>
			       		<td title="<%=l.getDatetime() %>" align="center" class="td2 txbtip" ><%=l.getDatetime() %>&nbsp;</td>
			       		<td title="<%=l.getLocale() %>" align="center" class="td2 txbtip" >
			       			<%if( 1 == l.getLocale()){ %>
			       			是&nbsp;
			       			<%}else{ %>
			       			否&nbsp;
			       			<%} %>
			       		</td>
			       		<td title="<%=l.getProjectProcess() %>" align="center" class="td2 txbtip" ><%=l.getProjectProcess() %>&nbsp;</td>
			       		<td title="<%=l.getDescr() %>" align="left" class="td2 txbtip" ><%=l.getDescr() %>&nbsp;</td>
							<%	User u = (User)request.getSession().getAttribute("session_user");
				       			if(u.getUsername().equals("admin") || l.getUser().getUsername().equals(u.getUsername())){
				       		 %>
					          <td align="center" class="td2 txbtip">
							     <a href="#" class='buttonlink txbtip' title='修改' onclick="editLabor(<%=l.getId()%>)"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/edit.png'/></a>
							     <img width='16' height='16' src='${pageContext.request.contextPath}/images/common/elbow-line.gif'/>
							      <a href="#" class='buttonlink txbtip' title='删除' onclick="delLabor('<%=l.getId()%>','你确定要删除？')" ><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/delete.png'/></a>
						      </td>
						      <td align="center" class="td2 txbtip">&nbsp;</td>
						      <%
						      	}else{
						       %>
							  <td align="center" class="td2 txbtip">&nbsp;</td>
				          		<%} %>
					</tr>	
				  <%}%>	
					
				</tbody>
			</table>
		</div>
			<script type="text/javascript" >
			
			function editLabor(id){
				AjaxUtil.request({
					url : 'editLabor.action',
					params : {id:id},
					success : function(responseText){
						PigossMsg.show("${pageContext.request.contextPath}/jsp/labor/editLabor.jsp","修改工时",470,480,"EditLabor.editConfig()");
					},
					failure : function(){
						PigossMsg.alert("修改失败!");
					}
				});
			};
			initTableWidget('dArticleList',Array('S','S',"S",'S','S','S',false));
				
				
			</script>
	</body>
</html>